<template>
    <div class="page" ref="topDiv">
        <Menu class="menu" mode="horizontal"  :active-name="1">
            <MenuItem name="1">{{title}}</MenuItem>
        </Menu>
        <div class="list">
            <div class="top_artical_div">
                <ul  class="articals" v-for = "(item,index) in articals">
                    <li class="artical">
                        <div class="articals_child" @click="toViewArtical(index)">
                            <p class="articals_child_title">{{item.infoTitle}}</p>
                            <p class="articals_child_date">{{item.createDate}}</p>
                        </div> 
                    </li>
                </ul>
            </div>
            <Row style="margin-right:10px;">
                <Col span="24" >
                    <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray" show-total show-sizer show-elevator />
                </Col>
            </Row>
        </div>
        <div class="down_info">
            <p class="down_red_line_4">一</p>
            <p class="down_red_line_1">一</p>
        </div>
    </div>
</template>

<script>


import {Api} from '../../../api/index.js'
import { sessionStorage, cookie } from '../../../common/cacheUtils.js';


export default {

     data() {
         return {
             title:"",
             articals:[],
             pageSizeArray: [10, 20, 50],
             pagedata: {
                total: 0,
                pageSize: 10,
                currentPage: 1,
            },
        }
    },
    mounted(){
        this.$refs.topDiv.style.height = (window.innerHeight - 120) + 'px';
        if(this.$route.query.type == "1"){
            this.title = "领导讲话"
        }else  if(this.$route.query.type == "2"){
            this.title = "活动资讯"
        }else{
            this.title = "有感领导"
        }
        this.$http.get(Api.getArticals+"?startPage="+this.pagedata.currentPage+"&size="+
            this.pagedata.pageSize+"&infoType="+this.$route.query.type).then(res => {
            if(res.data.status == 200){
                this.articals = res.data.data.data;
                this.articals.forEach(item=>{
                    item.createDate = this.formatDate(new Date(item.createDate), 'yyyy-MM-dd');
                });
                this.pagedata.total = res.data.data.totalSize;
            }
        }).catch(e => {
            this.$Message.error("数据获取失败")
        });
    },
    methods:{
        toViewArtical(index){
             this.$router.push({path:"/artical",query:{id:this.articals[index].infoId}});
        },
         pageChange(pageNum) {
            this.pagedata.currentPage = pageNum;
            this.query();
        },
        pageSizeChange(pageSize) {
            this.pagedata.pageSize = pageSize;
            this.query();
        },
        formatDate(date, fmt) {
            if (/(y+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
            }
            let o = {
                'M+': date.getMonth() + 1,
                'd+': date.getDate(),
                'h+': date.getHours(),
                'm+': date.getMinutes(),
                's+': date.getSeconds()
            };
            for (let k in o) {
                if (new RegExp(`(${k})`).test(fmt)) {
                    let str = o[k] + '';
                    fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
                }
            }
            return fmt;
        },
        padLeftZero(str) {
            return ('00' + str).substr(str.length);
        }
    }
}

</script>

<style scoped>
    @import '../../../index.css';
.page{
    display: flex;
    min-width:1250px;
    flex-direction: column;
    align-items: center;
    height: 100%;
    overflow-y:auto;
}

.menu{
    width:1200px;
}

.list{
    display: flex;
    flex-direction: column;
    width:1200px;
    flex-grow: 1;
}

.top_artical_div{ 
    flex-grow: 1;
}

.articals{
     min-width:1250px;
    background: #FFFFFF;
    align-items:flex-start;
}

.artical{
    margin-left: 15px;
    display: flex;
}

.articals_child{
    width:1150px;
    display: flex;
    justify-content: space-between;
}

.articals_child_title{
    width: 1000px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #333333;
    line-height: 32px;
    text-overflow:ellipsis;
    white-space:nowrap; 
    overflow:hidden;
}

.articals_child_date{
    width: 80px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #A3A3A3;
    line-height: 32px;
}

.articals_child:hover .articals_child_date,.articals_child:hover .articals_child_title{
    cursor: pointer; 
    color: #F65555;
}


ul {
    list-style-type: none;
}

.list ul li:before{ 
    display: inline-block;
    content: "O"; 
    padding-right: 10px;
    color: #FEA6A5;
    font-size:6px;
    line-height: 32px;
}


.down_info{
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 200px;
}

.down_red_line_4{
    margin-top:48px;
    width:1200px;
    height: 4px;
    color:white;
    background-color: red;
}

.down_red_line_1{
    margin-top:3px;
    width:1200px;
    height: 1px;
    color:white;
    background-color: red;
}

.down_company_info{
    margin: 24px;
    width: 1200px;
    height: 24px;
    text-align: center;
    font-size: 12px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #ADADAD;
    line-height: 24px;
}
</style>
